package com.example.hanfu.zhuanti;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.hanfu.R;

import java.util.ArrayList;

import androidx.annotation.NonNull;

public class ZhuanTiAdapter extends ArrayAdapter {
    private static final String TAG = "ZhuanTiAdapter";
    public ZhuanTiAdapter(@NonNull Context context, int resource, @NonNull ArrayList<ZhuanTi> list) {
        super(context, resource, list);
    }
    public View getView(int position, View convertView, ViewGroup parent) {
        View itemView=convertView;
        if(itemView==null){
            itemView= LayoutInflater.from(getContext()).inflate(R.layout.zhuanti_item,parent,
                    false);
        }
        ZhuanTi item=(ZhuanTi) getItem(position);
        TextView title=(TextView)itemView.findViewById(R.id.zhuanti_title);
        Log.i(TAG, "adapter:title=" + title);
        TextView href=(TextView)itemView.findViewById(R.id.zhuanti_href);
        Log.i(TAG, "adapter:href=" + href);
        ImageView img1=(ImageView) itemView.findViewById(R.id.zhuanti_img1);
        ImageView img2=(ImageView) itemView.findViewById(R.id.zhuanti_img2);
        ImageView img3=(ImageView) itemView.findViewById(R.id.zhuanti_img3);
        ImageView img4=(ImageView) itemView.findViewById(R.id.zhuanti_img4);
        Log.i(TAG, "adapter:img1=" + img1);
        Log.i(TAG, "adapter:img2=" + img2);
        Log.i(TAG, "adapter:img3=" + img3);
        Log.i(TAG, "adapter:img4=" + img4);

        //显示
        img1.setImageBitmap(item.getImg1());
        img2.setImageBitmap(item.getImg2());
        img3.setImageBitmap(item.getImg3());
        img4.setImageBitmap(item.getImg4());
        title.setText(item.getTitle());
        href.setText(item.getHref());

        return itemView;
    }


}
